package cn.micai.util;

import java.util.HashSet;
import java.util.Set;

/**
 * 描述：
 * <p>
 *
 * @author: 赵新国
 * @date: 2018/4/17 10:29
 */
public class SensitiveWordUtilTest {

    public static void main(String[] args) {

        Set<String> sensitiveWordSet = new HashSet<>();
        sensitiveWordSet.add("日本");
        sensitiveWordSet.add("韩国");
        sensitiveWordSet.add("美国");
        sensitiveWordSet.add("越南");
        sensitiveWordSet.add("法轮功");
        sensitiveWordSet.add("包夜");
        sensitiveWordSet.add("暴乱");
        sensitiveWordSet.add("违禁品");
        sensitiveWordSet.add("水果刀");
        sensitiveWordSet.add("菜刀");
        sensitiveWordSet.add("黄色");
        //初始化敏感词库
        SensitiveWordUtil.init(sensitiveWordSet);

        //System.out.println("敏感词的数量：" + SensitiveWordUtil.sensitiveWordMap.size());
        String string = "太多的日本伤感情怀也许美国只局限于饲养法轮功基地 荧幕中的情节。"
                + "然后我们的包夜扮演的角色就是暴乱跟随着主人公的喜红违禁品客联盟 怒哀乐而水果刀过于牵强的把自己的菜刀情感也附加于银幕情节中，然后感动就流泪，"
                + "难过就躺在某一个人的怀里尽情黄色的阐述心扉或者手机卡复制器一个贱人一杯红酒一部电影在夜 深人违禁品静的晚上，关上电话黄色静静的发呆着。";
        //System.out.println("待检测语句字数：" + string.length());

        //是否含有关键字
//        boolean result = SensitiveWordUtil.contains(string);
//        System.out.println(result);
//        result = SensitiveWordUtil.contains(string, SensitiveWordUtil.MinMatchTYpe);
//        System.out.println(result);

        //获取语句中的敏感词
//        Set<String> set = SensitiveWordUtil.getSensitiveWord(string);
//        System.out.println("语句中包含敏感词的个数为：" + set.size() + "。包含：" + set);
//        set = SensitiveWordUtil.getSensitiveWord(string, SensitiveWordUtil.MinMatchTYpe);
//        System.out.println("语句中包含敏感词的个数为：" + set.size() + "。包含：" + set);

        //替换语句中的敏感词
//        String filterStr = SensitiveWordUtil.replaceSensitiveWord(string, '*');
//        System.out.println(filterStr);
        String filterStr = SensitiveWordUtil.replaceSensitiveWord(string, '*', SensitiveWordUtil.MinMatchTYpe);
        System.out.println(filterStr);

//        String filterStr2 = SensitiveWordUtil.replaceSensitiveWord(string, "[*敏感词*]");
//        System.out.println(filterStr2);
//        filterStr2 = SensitiveWordUtil.replaceSensitiveWord(string, "[*敏感词*]", SensitiveWordUtil.MinMatchTYpe);
//        System.out.println(filterStr2);
    }
}
